package com.atguigu.gulimall.gulimallsearch.controller;

import com.atguigu.common.es.SkuEsModel;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.gulimallsearch.service.esService;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@RequestMapping("/es/action")
@RestController
public class esController {

    @Resource
    RestHighLevelClient restHighLevelClient;

    @Autowired
    esService esService;

    @RequestMapping("/index")
    public void testIndex() {
        System.out.println(restHighLevelClient);
    }


    @PostMapping("/saveEsModel")
    public R savaIndex(@RequestBody List<SkuEsModel> skuEsModelList) throws IOException {
        esService.saveModel(skuEsModelList);
        return R.ok();
    }


}
